<?php


namespace App\Http\observer;


use App\Engine\BaseCommon;
use App\Http\service\OssService;
use App\Jobs\OssUploadJob;
use App\Models\Image;
use Illuminate\Support\Facades\Log;
use App\Jobs\ComporessedImageJob;
use Illuminate\Support\Facades\Storage;

class ImageObserver
{

    public function creating(Image $image)
    {
        $url=public_path()."/".$image["url"];
        (new OssService())->uploadFile($image["url"],public_path()."/".$image["url"]);
       // OssUploadJob::dispatch($image);
    }

    public function deleted(Image $image)
    {
        $disk=Storage::disk("public");
        $disk->delete($image->url);
        try{
            (new OssService())->delFile($image->url);
        }catch (\Exception $exception){
            Log::error($exception->getMessage());
        }
    }
}
